package com.pamakids.utils
{
	import flash.events.EventDispatcher;
	import flash.external.ExtensionContext;
	import flash.utils.Dictionary;
	
	public class DeviceDescription extends EventDispatcher
	{
		/**
		 * 获取设备型号
		 */
		public static const KEY_MODEL:String = "getDeviceModel";
		/**
		 * 获取os版本号
		 */
		public static const KEY_OS_VERSION:String = "getOSVersion";
		/**
		 * 获取电话状态：
		 * 1. 无活动
		 * 2. 响铃
		 * 3. 摘机
		 */		
		public static const KEY_CALL_STATE:String = "getCallState";
		/**
		 * 电话方位
		 */
		public static const KEY_CELL_LOCATION:String = "getCellLocation";
		/**
		 * 设备ID
		 * GSM手机的IMEI 和 CDMA手机的MEID
		 * Return null if device ID is not available。
		 */
		public static const KEY_DEVICE_ID:String = "getDeviceId";
		/**
		 * 设备的软件版本号
		 * 例如：the IMEI/SV(software version) for GSM phones.
		 * Retrun null if the software version isnot available.
		 */
		public static const KEY_SOFTWARE_VERSION:String = "getSoftWareVersion";
		/**
		 * 手机号
		 * GSM手机的 MSISDN。
		 * Retrun null if it's unavailable.
		 */
		public static const KEY_PHONE_NUMBER:String = "getPhoneNumber";
		/**
		 * 获取手机类型，如
		 * PHONE_TYPE_NONE	无信号
		 * PHONE_TYPE_GSM	GSM信号
		 * PHONE_TYPE_CDMA	CDMA信号
		 */
		public static const KEY_PHONE_TYPE:String = "getPhoneType";
		/**
		 * 获取ISO国家码，相当于提供sim卡的国家码
		 */
		public static const KEY_SIM_COUNTRY_ISO:String = "getSimCountryIso";
		/**
		 * 服务商名称
		 * 例如：中国移动、联通
		 * SIM卡的状态必须是SIM_STATE_READY
		 */
		public static const KEY_SIM_OPERATOR_NAME:String = "getSimOperatorName";
		/**
		 * sim卡的序列号，需要权限：READ_PHONE_STATE
		 */
		public static const KEY_SIM_SERIAL_NUMBER:String = "getSimSerialNumber";
		/**
		 * 判断ICC卡是否存在
		 */		
		public static const KEY_HAS_ICC_CARD:String = "hasIccCard";
		/**
		 * 获取CPU序列号(16位)
		 * 读取失败则为'0000000000000000'
		 */		
		public static const KEY_CPU_SERIAL_NUMBER:String = "getCPUSerial";
		/**
		 * 通过GPS获取地理位置信息
		 */		
		public static const KEY_LOCATION_GPS:String = "getLocationByGPS";
		/**
		 * 通过NETWORK获取地理位置信息
		 */
		public static const KEY_LOCATION_NETWORD:String = "getLocationByNetwork";
		/**
		 * 获取SD卡信息
		 * return {
		 * 		hasSDCard:	boolean,
		 * 		freeSize:	Number,
		 * 		totalSize:	Number
		 * }
		 */		
		public static const KEY_SDCARD_INFO:String = "getSDCardInfo";
		
		
		private static const EXTENSION_ID:String="com.pamakids.DeviceDescription";
		
		private static const Dic:Dictionary = new Dictionary();
		
		private static function getDescription(key:String, reGet:Boolean=false):Object
		{
			if(reGet && Dic.hasOwnProperty(key))
				delete Dic[key];
				
			if(Dic.hasOwnProperty(key))
				return Dic[key];
			
			var context:ExtensionContext = ExtensionContext.createExtensionContext(EXTENSION_ID, null);
			if(!context)
				return "ERROR - Extension context is null. Please check if extension.xml is setup correctly.";
			
			Dic[key] = context.call('getDeviceInfo', key);
			context.dispose();
			return Dic[key];
		}
	}
}